package zhao.tx.eecs.zhao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import zhao.tx.eecs.R;
import zhao.tx.eecs.common.CommonActivity;

public class BookFrm extends CommonActivity {
	private ListAdapter adapter = null ;
	private List<Map<String, Object>> list = null;//数据
	private Handler handler=new Handler(){//http返回的处理
		@Override
		public void handleMessage(Message msg) {
			
		}
	};
		
    @Override
    public void onCreate(Bundle savedInstanceState) {    	
        super.onCreate(savedInstanceState);
        setContentView( R.layout.bookfrm);
        super.listViewAll = (ListView) findViewById(android.R.id.list);
        menu1 = (LinearLayout) findViewById(R.id.menu1);
        menu1.setOnTouchListener( view1);	
        menu2 = (LinearLayout) findViewById(R.id.menu2);
        menu2.setOnTouchListener( view2);	
        menu3 = (LinearLayout) findViewById(R.id.menu3);
        menu3.setOnTouchListener( view3);	
        
        View xhx1=(View)findViewById(R.id.xhx1);
        View xhx2=(View)findViewById(R.id.xhx2);
        View xhx3=(View)findViewById(R.id.xhx3);
        xhx3.setVisibility( View.VISIBLE);
		xhx2.setVisibility(View.GONE);
		xhx1.setVisibility(View.GONE);
        
        initDate();
    }
   
	//点击实现listview数据刷新，
	class listViewOnclickListener implements OnItemClickListener {
		
		@Override
		public void onItemClick(AdapterView<?> listt, View view, int position,long id) {			
			
		}
	}
	
	/**
	 * 设置一个适配器(把该适配器绑定到ListView上面)
	 */
	class ListAdapter extends BaseAdapter{
		private LayoutInflater inflater;
		
		public ListAdapter(Context context){        	
        	this.inflater = LayoutInflater.from(context);
        }
		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			Map<String, Object> mapzhao = list.get(position);
			TextView txt1;
			if(mapzhao.size()>2){
				convertView = inflater.inflate(R.layout.book_item, null);
				txt1=(TextView)convertView.findViewById(R.id.title);
				txt1.setText((String)mapzhao.get("v1"));
				txt1=(TextView)convertView.findViewById(R.id.info);
				txt1.setText((String)mapzhao.get("v2"));
			}
			else {
				convertView = inflater.inflate(R.layout.book_item2, null);
				txt1=(TextView)convertView.findViewById(R.id.title);
				txt1.setText((String)mapzhao.get("v1"));
			}
			
			return convertView;
		}		
	}
	
	 
    /**
     * 获取ListView的数据
     * @return
     */
	private List<Map<String, Object>> getDate() {
		
		List<Map<String, Object>> listLitong = new ArrayList<Map<String, Object>>();
		Map<String, Object> maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "北京电务段");
		listLitong.add(maplitong);

		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		    
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "黄村车段");
		listLitong.add(maplitong);

		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		    
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);

		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "廊坊高铁工期");
		listLitong.add(maplitong);

		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		    
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "刘芳");
		maplitong.put("v2", "负责行车调度");
		maplitong.put("v3", "13598321234");
		maplitong.put("v4", "url");
		listLitong.add(maplitong);
			  
		return listLitong;
	}
  
	/**
	 * 拿到整个数据List的大小</br> 如果List不等于空 或者 List的大小大于零</br>
	 * 实例化一个自定义的适配器,把自定义的适配器绑定到控件ListView上面</br>
	 * 实例化一个自定义的监听器,把自定义的监听器绑定到控件ListView上面</br> 判断屏幕的密度 </br> 如果密度小于1.0
	 * 密度等于1.5</br> 就给ListView手动设置宽度和高度</br>
	 */
	private void initDate(){
		list = getDate();
		if(list != null && list.size() > 0 ){
			adapter = new ListAdapter(this);
			super.listViewAll.setAdapter(adapter);
			super.listViewAll.setOnItemClickListener(new listViewOnclickListener());
			
		}
	}
	public void btn_shebei_click(View v) {	
		 
		 Intent intent = new Intent();		 
		 intent.setClass(getApplicationContext(), PD_Shaomiao.class);
		 startActivity(intent);
	}
}
    
    

